import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/bean/IndustryItemBean.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/AccidentTreatment.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ImageHelper.dart';
import 'package:ysy_flutter_mvvm_yuanxuan/helper/ViewHelper.dart';

//工业
class Industry extends StatefulWidget {
  @override
  _IndustryState createState() => _IndustryState();
}

class _IndustryState extends State<Industry> {
  @override
  Widget build(BuildContext context) {
    var gongyes = gongyeDatas();
    var of = MediaQuery.of(context);
    var top = of.padding.top;
    var size = of.size;
    return Container(
      color: Color(0xffF5F6F8),
      padding: EdgeInsets.fromLTRB(0, top+12, 0, 0),
      child: Column(
         children: [
           Container(
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.fromLTRB(12.w, 12.h, 12.w, 12.h),
              child: Text("工业",style: TextStyle(color: Color(0xff2D3137),fontSize: 20.sp,fontWeight:FontWeight.w600),textAlign: TextAlign.left,),
            ),
            //工业APP
            Container(
               decoration: BoxDecoration(color: Colors.white,borderRadius: BorderRadius.all(Radius.circular(GenericViewParameters.bgRoundedCorners))),
               padding: EdgeInsets.fromLTRB(12.w, 12.h, 12.w, 12.h),
               margin: EdgeInsets.fromLTRB(12.w, 12.h, 12.w, 12.h),
               child: Column(
                 children: [
                   Container(
                     alignment: Alignment.centerLeft,
                     padding: EdgeInsets.fromLTRB(0.w, 0.h, 0.w, 12.h),
                     child: Text("工业APP",style: TextStyle(color: Color(0xff333333),fontSize: 15.sp,fontWeight:FontWeight.w600),textAlign: TextAlign.left,),
                   ),
                   Container(
                     margin: EdgeInsets.fromLTRB(0.w, 24.h, 0.w, 0.h),
                     height: calculateHeight(76.w,gongyes.length,4),
                     alignment: Alignment.bottomLeft,
                     child: GridView.builder(
                         itemCount: gongyes.length,
                         padding: EdgeInsets.zero,
                         gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4,mainAxisExtent: 76.h ),
                         itemBuilder: (BuildContext context, int index){
                         return IndustryItem(index,gongyes[index]);
                     }),
                   ),
                 ],
               ),
            )
         ],
      ),
    );
  }
}

class IndustryItem extends StatelessWidget {

  IndustryItemBean _industryItemBean;
  int  index;

  IndustryItem(this.index,this._industryItemBean);

  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    return Container(
        alignment: index==0?Alignment.centerLeft:(index==3?Alignment.centerRight:Alignment.center),
        child: Column(
          children: [
             Image.asset(assetPath(_industryItemBean.ic),width: 36.w,height: 36.w),
             Padding(padding: EdgeInsets.fromLTRB(0, 10.h, 0, 0)),
             Text(_industryItemBean.name,style: TextStyle(color: Color(0xff2D3137),fontSize: 12.sp),textAlign: TextAlign.center,),
          ],
        ),
    );
  }
}

List<IndustryItemBean> list=[];

List<IndustryItemBean> gongyeDatas(){
  if(list.isEmpty){
    list.add(IndustryItemBean("设备APP","ic_gy_yuansheng.png","",""));
    list.add(IndustryItemBean("材料库","ic_cailiaoku.png","",""));
  }
  return list;
}


